package whu.o2o.adapter;

import java.util.ArrayList;

import whu.o2o.util.ConstantData;
import whu.o2o.util.Utils;
import whu.o2o.vo.ImageVO;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import whu.o2o.R;

public class DiaryImageAdapter extends BaseAdapter {
	public ArrayList<ImageVO> publicList;
	private Context mContext;
	private int mImageSize;
	
	public DiaryImageAdapter(Context context, ArrayList<ImageVO> imageList) {
		mContext = context;
		publicList = imageList;
		mImageSize = Utils.dip2px(mContext, 70);
	}

	@Override
	public int getCount() {
		return publicList.size();
	}

	@Override
	public Object getItem(int position) {
		return publicList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageVO imageVO = publicList.get(position);

		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();

			ImageView imageView = new ImageView(mContext);
			imageView.setLayoutParams(new GridView.LayoutParams(mImageSize, mImageSize));
			imageView.setScaleType(ScaleType.CENTER_CROP);
			
			convertView = imageView;
			holder.image = (ImageView) convertView;

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if (imageVO.getThumbnailPath().equals(ConstantData.Data.ADD_IMAGE_TAG)) {
			holder.image.setImageResource(R.drawable.btn_add_image_sel);
		}else{
			//holder.image.setImageResource(R.drawable.ic_main_route);
		}
		
		return convertView;
	}

	static class ViewHolder {
		ImageView image;
	}
}
